package com.isunland.managesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.ScoreMonthAssign;
import java.util.ArrayList;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/6/16 16:52
 */
public class ScoreMonthAssignAdapter extends BaseExpandableListAdapter {

  private ArrayList<ScoreMonthAssign> mList = new ArrayList<>();
  private LayoutInflater inflater;
  private Context context;

  public ScoreMonthAssignAdapter(Context context, ArrayList<ScoreMonthAssign> mSuperList) {
    this.mList = mSuperList;
    this.context = context;
    this.inflater = LayoutInflater.from(context);
  }

  @Override public int getGroupCount() {
    return mList.size();
  }

  @Override public int getChildrenCount(int groupPosition) {
    if (mList.size() > 0) {

      return mList.get(groupPosition).getSubList().size();
    } else {
      return 0;
    }
  }

  @Override public Object getGroup(int groupPosition) {

    return mList.get(groupPosition);
  }

  @Override public Object getChild(int i, int i1) {
    return null;
  }

  @Override public long getGroupId(int groupPosition) {
    return groupPosition;
  }

  @Override public long getChildId(int groupPosition, int childPosition) {
    return childPosition;
  }

  @Override public boolean hasStableIds() {

    return true;
  }

  //  获得父项显示的view
  @Override public View getGroupView(int groupPosition, boolean b, View convertView,
      ViewGroup parent) {
    if (convertView == null) {
      convertView = inflater.inflate(R.layout.item_score_dept, parent, false);
    }
    TextView tvMonth = (TextView) convertView.findViewById(R.id.tv_month);//月份
    TextView tvDept = (TextView) convertView.findViewById(R.id.tv_dept);//部门
    TextView tvSumScore = (TextView) convertView.findViewById(R.id.tv_sumScore);//部门总分
    ScoreMonthAssign content = mList.get(groupPosition);
    tvMonth.setText(content.getRemark());
    tvDept.setText(content.getInOrgName());
    tvSumScore.setText(content.getRewValue());
    return convertView;
  }

  //  获得子项显示的view
  @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
      View convertView, ViewGroup parent) {

    if (convertView == null) {
      convertView = inflater.inflate(R.layout.item_score_person, parent, false);
    }
    ScoreMonthAssign.SubListBean subContent =
        mList.get(groupPosition).getSubList().get(childPosition);
    TextView tvPerson = (TextView) convertView.findViewById(R.id.tv_person);
    TextView tvSumScore = (TextView) convertView.findViewById(R.id.tv_sumScore);
    tvPerson.setText(subContent.getInStaffName());
    tvSumScore.setText(subContent.getRewValue());

    return convertView;
  }

  //  子项是否可选中，如果需要设置子项的点击事件，需要返回true
  @Override public boolean isChildSelectable(int i, int i1) {
    return false;
  }

  @Override public boolean isEmpty() {
    return true;
  }
}
